package com.yunzheng.util;

import com.yunzheng.constants.SystemConstants;
import com.yunzheng.redis.RedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *
 * </p>
 *
 * @author 杜奕明
 * @date 2020/1/18
 */
@Component
public class TokenParser {

//    @Autowired
//    private UserMapper userMapperTemp;

    @Autowired
    private RedisManager redisManagerTemp;

//    @Autowired
//    private AdminUserMapper adminUserMapperTemp;

//    private static UserMapper userMapper;

    private static RedisManager redisManager;

//    private static AdminUserMapper adminUserMapper;
//
//    @PostConstruct
//    public void init() {
//        userMapper = userMapperTemp;
//        redisManager = redisManagerTemp;
//        adminUserMapper = adminUserMapperTemp;
//    }

    public static Long token2UserIdL(HttpServletRequest request) {
        return Long.valueOf((String) redisManager.get(request.getHeader(SystemConstants.TOKEN)));
    }

    public static String token2UserId(HttpServletRequest request) {
        return String.valueOf(redisManager.get(request.getHeader(SystemConstants.TOKEN)));
    }

//    public static User token2User(HttpServletRequest request) {
//        return userMapper.selectById(token2UserId(request));
//    }

//    public static AdminUser token2AdminUser(HttpServletRequest request){
//        return adminUserMapper.selectById(token2UserId(request));
//    }
}
